package com.itheima.web.controller.oms;

import com.itheima.dto.oms.OrderDeliveryDto;
import com.itheima.dto.oms.OrderMoneyDto;
import com.itheima.dto.oms.OrderPageDto;
import com.itheima.dto.oms.OrderReceiverDto;
import com.itheima.service.oms.IOmsOrderService;
import com.itheima.utils.PageResult;
import com.itheima.utils.ResultData;
import com.itheima.vo.oms.OrderDetailVo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/order")
public class OmsOrderController {
   @DubboReference
   private IOmsOrderService omsOrderService;

   /**
    * 批量删除订单
    */
   @PostMapping("/delete")
   public ResultData delete(@RequestParam List<Integer> ids) {
    omsOrderService.delete(ids);
      return ResultData.ok("删除成功!","");
   }
    /**
     * 分页查询订单详情
     *
     * @param dto
     * @return
     */
    @GetMapping("/list")
    public ResultData list(OrderPageDto dto) {
        PageResult vo = omsOrderService.list(dto);
        return ResultData.ok("",vo);
    }
    /**
     * 修改订单费用信息
     */
    @PostMapping("/update/moneyInfo")
    public ResultData updateMoneyInfo(@RequestBody OrderMoneyDto dto) {
        omsOrderService.updateOrderMoney(dto);
        return ResultData.ok("修改成功!","");
    }
    /**
     * 修改收货人信息
     */
    @PostMapping("/update/receiverInfo")
    public ResultData updateReceiverInfo(@RequestBody OrderReceiverDto dto) {
        omsOrderService.updateOrderReceiver(dto);
        return ResultData.ok("修改成功!","");
    }

    /**
     * 批量关闭订单
     */
    @PostMapping("/update/close")
    public ResultData close(@RequestParam Map map) {
        omsOrderService.close(map);
        return ResultData.ok("关闭订单成功!","");
    }
    /**
     * 批量发货
     */
    @PostMapping("/update/delivery")
    public ResultData delivery(@RequestBody List<OrderDeliveryDto> list) {
        omsOrderService.delivery(list);
        return ResultData.ok("发货成功!","");
    }
    /**
     * 根据订单id获取订单详情
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResultData findOrderDetails(@PathVariable Integer id) {
        OrderDetailVo vo = omsOrderService.findById(id);
        return ResultData.ok("",vo);
    }

    /**
     * 备注订单
     */
    @PostMapping("/update/note")
    public ResultData note(@RequestParam Map<String, String> map) {
        Integer count = omsOrderService.note(map);
        if (count == 0) {
            return ResultData.error("备注失败!");
        }
        return ResultData.ok("备注成功!","");
    }
}
